﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Test1();
            //Test2();
            //Test3();
            //Test4();
            //Test5();
            //Test6();
            //Test7();
            //Test8();
            //Test9();
            Test10();
            //Test11();
        }

        static void Test1()
        {
            Console.WriteLine("下标为偶数的元素");
            string[] arr = { "abc", "def", "ghi" };

            for (int i = 0; i < arr.Length; i++)
            {
                if (i % 2 == 0)
                {
                    Console.WriteLine(arr[i]);
                }
            }
        }

        static void Test2()
        {
            Console.WriteLine("统计字符");
            Console.WriteLine("请输入一串字符串：");
            string a = Console.ReadLine();

            int c = 0;
            int d = 0;
            int e = 0;

            foreach (char b in a)
            {
                if (char.IsLetter(b))
                {
                    c++;
                }
                else if (char.IsDigit(b))
                {
                    d++;
                }
                else if (char.IsSeparator(b))
                {
                    e++;
                }
            }
            Console.WriteLine("输入的字符串中英文字母有{0}个，数字有{1}个，空格有{2}个", c, d, e);
        }
        static void Test3()
        {
            Console.WriteLine("统计总分，平均分");
            double[] arr = new double[5];
            double a = 0;

            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine("请输入学生的成绩：");
                arr[i] = double.Parse(Console.ReadLine());
            }

            foreach (double num in arr)
            {
                a = a + num;
            }

            double b = a / 5;
            Console.WriteLine("总分是：{0}", a);
            Console.WriteLine("平均分是：{0}", b);
        }

        static void Test4()
        {
            Console.WriteLine("排序");
            int[] arr = { 25, 15, 35, 65, 45, 55 };
            int index = 0;
            Console.WriteLine("排序前：");

            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + " ");
            }
            for (int i = 0; i < arr.Length - 1; i++)
            {
                for (int j = 0; j < arr.Length - i - 1; j++)
                {
                    if (arr[j] < arr[j + 1])
                    {
                        index = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = index;
                    }
                }
            }
            Console.WriteLine();
            Console.WriteLine("排序后：");

            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + " ");
            }
            Console.WriteLine();
        }

        static void Test5()
        {
            Console.WriteLine("找元素");
        asd:
            int index = -1;
            int[] arr = { 25, 15, 35, 65, 45, 55, 55 };
            Console.WriteLine("请输入要查找的数：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 0; i < arr.Length; i++)
            {
                if (a == arr[i])
                {
                    index = i;
                }
            }

            if (index == -1)
            {
                Console.WriteLine("没找到！请重新输入！");
                goto asd;
            }
            else
            {
                Console.WriteLine("{0}在数组中的位置是{1}", a, index);
            }

        }
        static void Test6()
        {
            Console.WriteLine("乘法表");
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j < 10; j++)
                {
                    if (j <= i)
                    {
                        Console.Write(i + "*" + j + "=" + i * j + "\t");
                    }

                }
                Console.WriteLine();
            }
        }
        static void Test7()
        {
            Console.WriteLine("空心正方形");
            Console.WriteLine("请输入正方形的边长：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    if (i == 0 || j == 0 || j == a - 1 || i == a - 1)
                    {
                        Console.Write("*" + " ");
                    }
                    else
                    {
                        Console.Write(" " + " ");
                    }
                }
                Console.WriteLine();
            }
        }

        static void Test8()
        {
            Console.WriteLine("菱形");
            Console.WriteLine("请输入菱形的边长：");
            int n = int.Parse(Console.ReadLine());

            for (int i = 1; i <= n; i++)
            {
                for (int j = n - 1; j >= i; j--)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i * 2 - 1; k++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            for (int i = n - 1; i >= 1; i--)
            {
                for (int j = i - 1; j < n - 1; j++)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i * 2 - 1; k++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
        static void Test9()
        {
            Console.WriteLine("实心正方形");
            Console.WriteLine("请输入正方形的边长：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    Console.Write("*" + " ");
                }
                Console.WriteLine();
            }
        }
        static void Test10()
        {
            Console.WriteLine("杨辉三角形");
            int[][] arr = new int[10][];

            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr[i].Length; j++)
                {
                    arr[i][j] = 1;
                }
            }

            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr[i].Length; j++)
                {
                    Console.WriteLine(arr[i][j]);
                }
            }
        }
        static void Test11()
        {
            Console.WriteLine("插入排序");
            int[] arr1 = { 50, 40, 30, 20, 10 };
            Console.WriteLine("插入前：");

            for (int i = 0; i < arr1.Length; i++)
            {
                Console.Write(arr1[i] + "\t");
            }
            Console.WriteLine();

            int[] arr2 = new int[arr1.Length+1];
            Console.WriteLine("请输入一个数：");
            int a = int.Parse(Console.ReadLine());
            int index = 0;

            for (int i = 0; i < arr1.Length; i++)
            {
                arr2[i] = arr1[i];
            }
            arr2[arr2.Length - 1] = a;


            for (int i = 0; i < arr2.Length - 1; i++)
            {
                for (int j = 0; j < arr2.Length - i - 1; j++)
                {
                    if (arr2[j] < arr2[j + 1])
                    {
                        index = arr2[j];
                        arr2[j] = arr2[j + 1];
                        arr2[j + 1] = index;
                    }
                }
            }
            Console.WriteLine("插入后：");

            for (int i = 0; i < arr2.Length; i++)
            {
                Console.Write(arr2[i] + "\t");
            }
            Console.WriteLine();
        }
    }
}
